package com.ssx.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ssx.entity.Customer;
import com.ssx.entity.Customershare;
import com.ssx.mapper.CustomershareMapper;
import com.ssx.service.ICustomershareService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ssx
 * @since 2020-10-24
 */
@Service
@Transactional
public class CustomershareServiceImpl extends ServiceImpl<CustomershareMapper, Customershare> implements ICustomershareService {

    @Autowired
    private CustomershareMapper customershareMapper;
    @Override
    public List<Customer> listFromEmp(int start, int pagesize, String search, int empid) {
        List<Customershare> customershares = customershareMapper.selectList(new QueryWrapper<Customershare>()
                .eq("empid", empid).last(" limit " + start + "," + pagesize));
        List<Customer> list=new ArrayList<>();
        for (Customershare customershare :customershares ) {
            list.add(customershare.getCustomer());
        }
        return list;
    }

    @Override
    public int countFromEmp(String search, int empid) {
        return customershareMapper.selectList(new QueryWrapper<Customershare>().eq("empid",empid)).size();
    }
}
